﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sunimage.Spjg.BLL.SysMgr;
using Sunimage.Spjg.Common.SysMgr;
using Sunimage.Spjg.Web.Helper;
using Sunimage.Spjg.Web.UserControls;
using Sunimage.Spjg.Common.Exceptions;
using Sunimage.Spjg.Common;
using System.Data.SqlClient;

namespace Sunimage.Spjg.Web.Admin
{
    public partial class UsersAdd : System.Web.UI.Page
    {
        UserBl gsjUserBl = new UserBl();

        protected void btnSaveNewUser_Click(object sender, EventArgs e)
        {
            User user = new User();
            user.Username = tbxUsernameAdd.Text.Trim();
            user.Password = tbxPasswordAdd.Text;
            user.Email = tbxEmail.Text.Trim();
            user.NickName = tbxNickname.Text.Trim();
            user.Role = (RoleType)Convert.ToInt32(ddlRole.SelectedValue);

            try
            {
                gsjUserBl.CreateUser(user);
                // BindUsers();
                //MessageHelper.RegShowJSAjax(btnSaveNewUser, "添加用户成功", this.Page);
                Response.Redirect("Users.aspx");
            }
            catch (ApplicationException excp)
            {
                //mpeNewUser.Show();
                //AlertHelper.ShowError(excp.Message, this.Page);
                AlertHelper.ShowError("发生错误，请联系系统管理员", this.Page);
            }
        }

        protected void btnCancelNewCommercer_Click(object sender, EventArgs e)
        {
            Response.Redirect("Users.aspx");
        }
    }
}